package com.nondo.dean.order.model.result;

import java.math.BigDecimal;
import java.util.List;

import com.nondo.dean.common.tool.BeanUtils;
import com.nondo.dean.order.domain.Cart;

public class AppCartResult {
    /**
     * 总数
     */
    private int total;
    /**
     * 产品总价
     */
    private BigDecimal totalPrice;
    /**
     * 购物车列表
     */
    private List<CartBean> cartList;

    /**
     * @return the total
     */
    public int getTotal() {
        return total;
    }

    /**
     * @param total the total to set
     */
    public void setTotal(int total) {
        this.total = total;
    }

    /**
     * @return the totalPrice
     */
    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    /**
     * @param totalPrice the totalPrice to set
     */
    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    /**
     * @return the cartList
     */
    public List<CartBean> getCartList() {
        return cartList;
    }

    /**
     * @param cartList the cartList to set
     */
    public void setCartList(List<CartBean> cartList) {
        this.cartList = cartList;
    }

    public static class CartBean {
        /**
         * 购物车主键ID
         */
        private Integer id;

        /**
         * 产品ID
         */
        private Integer productId;

        /**
         * 产品名称
         */
        private String productName;
        
        /**
         * 产品主图
         */
        private String mainImage;
        
        /**
         * 产品描述
         */
        private String descrption;
        
        /**
         * 产品单价
         */
        private String price;

        /**
         * 产品数量
         */
        private Integer num;
        
        /**
         * 定制内容
         */
        private String note;
        
        /**
         * 组合产品
         */
        private int isMix;

        /**
         * @return the id
         */
        public Integer getId() {
            return id;
        }

        /**
         * @param id the id to set
         */
        public void setId(Integer id) {
            this.id = id;
        }

        /**
         * @return the productId
         */
        public Integer getProductId() {
            return productId;
        }

        /**
         * @param productId the productId to set
         */
        public void setProductId(Integer productId) {
            this.productId = productId;
        }

        /**
         * @return the productName
         */
        public String getProductName() {
            return productName;
        }

        /**
         * @param productName the productName to set
         */
        public void setProductName(String productName) {
            this.productName = productName;
        }

        /**
         * @return the mainImage
         */
        public String getMainImage() {
            return mainImage;
        }

        /**
         * @param mainImage the mainImage to set
         */
        public void setMainImage(String mainImage) {
            this.mainImage = mainImage;
        }

        /**
         * @return the descrption
         */
        public String getDescrption() {
            return descrption;
        }

        /**
         * @param descrption the descrption to set
         */
        public void setDescrption(String descrption) {
            this.descrption = descrption;
        }

        /**
         * @return the price
         */
        public String getPrice() {
            return price;
        }

        /**
         * @param price the price to set
         */
        public void setPrice(String price) {
            this.price = price;
        }

        /**
         * @return the num
         */
        public Integer getNum() {
            return num;
        }

        /**
         * @param num the num to set
         */
        public void setNum(Integer num) {
            this.num = num;
        }

        /**
         * @return the note
         */
        public String getNote() {
            return note;
        }

        /**
         * @param note the note to set
         */
        public void setNote(String note) {
            this.note = note;
        }

        public int getIsMix() {
            return isMix;
        }

        public void setIsMix(int isMix) {
            this.isMix = isMix;
        }

    }

    /**
     * 将数据库中的购物车赋值给当前购物车对象
     * @param cart
     * @return
     */
    public static CartBean covertToBean(Cart cart) {
        CartBean cartBean = new CartBean();
        BeanUtils.copy(cart, cartBean);
        return cartBean;
    }

    /**
     * 将数据库中的产品属性赋值给当前购物车对象
     * @param productResult
     * @return
     */
    public static CartBean covertToBean(ProductResult productResult) {
        CartBean cartBean = new CartBean();
        BigDecimal salePrice = productResult.getSalePrice();
        cartBean.setPrice(salePrice.toPlainString());
        cartBean.setProductId(productResult.getId());
        cartBean.setProductName(productResult.getName());
        BeanUtils.copy(productResult, cartBean);
        return cartBean;
    }

}